package com.zhang.family_doctor.controller;

import com.github.pagehelper.PageInfo;
import com.zhang.family_doctor.entity.R;
import com.zhang.family_doctor.entity.Tag;
import com.zhang.family_doctor.entity.Team;
import com.zhang.family_doctor.service.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 标签模块管理
 */
@RestController
@RequestMapping("/tag")
@Slf4j
@Api(tags = "标签模块管理")
public class TagController {

    @Autowired
    private TagService tagService;

    @ApiOperation("新增标签")
    @PostMapping("/save")
    public R<String> save(@RequestBody Tag tag, HttpServletRequest request){
        log.info("新增标签：{}",tag);
        return tagService.save(tag,request);
    }

    @ApiOperation("修改标签")
    @PostMapping("/update")
    public R<String> update(@RequestBody Tag tag,HttpServletRequest request){
        log.info("修改标签：{}",tag);
        return tagService.update(tag,request);
    }

    @ApiOperation("分页查询标签")
    @GetMapping("/getList")
    public R<PageInfo<Tag>> getList(@RequestParam(value = "pageNum",required = true) Integer pageNum, @RequestParam(value = "pageSize",required = true) Integer pageSize, @RequestParam(value = "name",required = false) String name){
        log.info("分页查询标签：{}",pageNum);
        return tagService.getList(pageNum,pageSize,name);
    }

    @ApiOperation("根据id删除标签")
    @DeleteMapping("/delete")
    public R<String> delete(Integer id){
        log.info("根据id删除标签：{}",id);
        return tagService.delete(id);
    }

    @ApiOperation("启用或禁用标签")
    @PostMapping("/enableOrDisable")
    public R<String> enableOrDisable(Integer id,Integer state){
        log.info("启用或禁用标签：{}",id);
        return tagService.enableOrDisable(id,state);
    }



}
